package com.itheima.youdianda.controller;

import cn.hutool.core.convert.Convert;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.pojo.YddArticle;
import com.itheima.youdianda.service.YddArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/ydd_article")
public class YddArticleController {
    @Autowired
    private YddArticleService yddArticleService;

    /**
     * 文章列表-分页
     */
    @GetMapping("/list")
      public R getPage(@RequestParam String start_time,String end_time,String title,String cateid,String page,String limit){
//    public R getPage(@RequestParam Map<String,String>  map/*String startTime,String endTime,String title,String cateid,String page,String limit*/){
        Long page1 = Convert.toLong(page);
        Long pageSize = Convert.toLong(limit);

        return yddArticleService.getPage(start_time,end_time,cateid,title,page1,pageSize);
    }
    /**
     * 删除文章
     */
    @GetMapping("/del")
    public R deleteYddarticle(@RequestParam Integer id){
        return yddArticleService.deleteYddarticle(id);
    }
    /**
     * 查看详情(数据回显)
     */
    @GetMapping("/rowInfo")
    public R getYddarticleById(@RequestParam Integer id){
        return yddArticleService.getYddarticleById(id);
    }

    /**
     * 修改文章
     */
    @PostMapping("/update")
    public R updateYddarticle(@RequestBody YddArticle yddArticle){
        return yddArticleService.updateYddarticle(yddArticle);
    }
    /**
     * 添加文章
     */
    @PostMapping("/add")
    public R addYddarticle(@RequestBody YddArticle yddArticle){
        return yddArticleService.addYddarticle(yddArticle);
    }

}
